home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 397 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  60 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: 71247.3221@compuserve.com (Don Wallace)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Legal C++ code?
  5. Date: 20 Feb 1996 15:44:51 GMT
  6. Organization: CompuServe Incorporated
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4gbilr$38m@dub-news-svc-1.compuserve.com>
  9. References: <4fvtk3$16j@cnn.Princeton.EDU>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Content-Type: text
  12. X-Nntp-Posting-Host: hd48-175.compuserve.com
  13. X-Newsreader: Forte Free Agent v0.55
  14. Content-Length: 824
  15. X-Lines: 35
  16. Originator: clamage@taumet
  17.  
  18. tim@franck.Princeton.EDU (Tim Hollebeek) wrote:
  19.  
  20. >Is the following legal C++ code?  g++ compiles it, but it doesn't link
  21. >(undefined function Foo::foo()).  I'm suprised it compiles at all:
  22.  
  23. >class Foo {
  24. >public:
  25. >    virtual int foo() = 0;
  26. >};
  27.  
  28. >class Bar : public Foo {
  29. >public:
  30. >    int foo() { return Foo::foo(); }
  31. >};
  32.  
  33. >int main() {
  34. >    Bar bar;
  35. >    bar.foo();
  36. >}
  37.  
  38. I suspect that this is perfectly legal C++ code. Every statement taken
  39. individually is correct. But even if it linked, the net effect of
  40. calling bar.foo() would be to attempt to activate a pure virtual
  41. function (In Borland C++ this generates a RTL program halt - it says
  42. 'pure virtual function called'.)
  43.  
  44. The statement/function 
  45.  
  46. >    int foo() { return Foo::foo(); }
  47.  
  48. refers to Foo::foo() which is inherently not defined. Hence the link
  49. error.
  50.  
  51. - Don
  52.  
  53.  
  54. [ To submit articles: Try just posting with your newsreader.  If that fails,
  55.               use mailto:std-c++@ncar.ucar.edu
  56.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  57.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  58.   Comments? mailto:std-c++-request@ncar.ucar.edu
  59. ]
  60.